<template>
  <van-pull-refresh v-model="isRefreshLoading" @refresh="onLoad">
    <MyEmpty v-if="isLoading === false && list.length === 0" />
    <van-list class="my-resume-list" v-model="isLoading" :finished="finished" finished-text="没有更多了" @load="onLoad" v-else>
      <div class="item" v-for="(item, index) in list" :key="index" @click="onItemClick(item, index)">
        <div class="show">
          <div class="person">
            <img :src="item.logo" alt="" v-if="item.logo != ''" />
            <template v-else>
              <img src="@/assets/img/my/no-avatar-boy.png" alt="" v-if="item.sex === '男'" />
              <img src="@/assets/img/my/no-avatar-girl.png" alt="" v-else />
            </template>
            <p>
              <b>{{ item.name }}</b>
              <span :class="{ unread: item.isRead === '未读' }">{{
                item.isRead
              }}</span>
            </p>
            <p>
              <span>{{ item.sex }}</span>
              <span>{{ item.age }}岁</span>
              <span>{{ item.edu }}</span>
              <span>{{ item.workyear }}</span>
            </p>
          </div>
          <div class="apply">
            <span class="txt01">{{ item.jobname }}</span>
            <span>{{ item.showDate }}</span>
          </div>
        </div>
      </div>
    </van-list>
  </van-pull-refresh>
</template>

<script>
import { List, Button, SwipeCell, PullRefresh } from "vant";
import MyEmpty from "@/components/MyEmpty.vue";
import { CompanyResumeGetInboxList } from "@/util/http";
import { mixin_company_common } from "@/mixin/mixins";
import Global from "@/Global";
export default {
  name: "InboxContent",
  components: {MyEmpty,[List.name]: List,[Button.name]: Button,[SwipeCell.name]: SwipeCell,[PullRefresh.name]: PullRefresh,},
  mixins: [mixin_company_common],
  mounted() {
    // this.onLoad();
    this.$bus.$on(Global.bus_company_resume_inbox_update, (res) => {
      this.isRefreshLoading = true;
      this.onLoad();
    });
  },
  // 定义属性
  data() {
    return {
      isRefreshLoading: false,
      list: [],
      page: 0,
      isLoading: true,
      finished: false,
    };
  },
  // 方法集合
  methods: {
    onLoad() {
      if (this.isRefreshLoading) {
        this.page = 0;
      }
      let page = this.page;
      page++;
      this.page = page;

      CompanyResumeGetInboxList(page, "正常").then((res) => {
        // console.log(res);
        this.isLoading = false;
        if (this.isRefreshLoading) {
          this.list = [];
        }
        this.isRefreshLoading = false;
        let list = res.list;
        if (list.length > 0) {
          this.list = [...this.list, ...list];
          this.finished = false;
        } else {
          this.finished = true;
        }
      });
    },
    onItemClick(item, index) {
      this.toViewResume(item.resumeid, item.id);
      item.isRead = "已读";
      this.list.splice(index, 1, item);
    },
  },
};
</script>

<style scoped></style>
